﻿/********************************************************
 * 类名：SystemManageHandler.cs
 * 功能：
 *   ver	变更日		作者			变更内容
 * ────────────────────────────────────────
 *   V01.0	2013-11-27	李波			初版
 *
 * Copyright (c) 2013，李波版权所有
 ********************************************************/
using System;
using System.Web;
using System.Web.SessionState;
using PSS.BLL.SystemManage;
using PSS.Entity.SystemManage;
using PSS.Utility;

namespace PSS.WebSite.Service
{
    /// <summary>
    /// SystemManageHandler 的摘要说明
    /// </summary>
    public class SystemManageHandler : IHttpHandler, IRequiresSessionState
    {
        public void ProcessRequest(HttpContext context)
        {
            try
            {
                var action = StrRequest.GetQueryString("action");
                if (string.IsNullOrEmpty(action)) return;
                var method = this.GetType().GetMethod(action);
                if (method == null) return;
                object[] parameters = { context };
                method.Invoke(this, parameters);
            }
            catch (Exception ex)
            {
                EventsLog.WriteLog("程序错误：" + ex.Message);
            }
        }

        #region 系统菜单
        public void LoadMenuList(HttpContext context)
        {
            try
            {
                var loginCode = "admin";//SysContext.CurrentLoginCode;
                if (string.IsNullOrEmpty(loginCode)) return;
                var json = new MenuBLL().LoadMenuList(loginCode);
                context.Response.Write(json);
                context.Response.End();
            }
            catch (Exception ex)
            {
                EventsLog.WriteLog("程序错误：" + ex.Message);
            }
        }
        public void GetMenuList(HttpContext context)
        {
            try
            {
                var json = new MenuBLL().GetMenuList();
                context.Response.Write(json);
                context.Response.End();
            }
            catch (Exception ex)
            {
                EventsLog.WriteLog("程序错误：" + ex.Message);
            }
        }
        public void GetMenuParentNode(HttpContext context)
        {
            try
            {
                var json = new MenuBLL().GetMenuParentNode();
                context.Response.Write(json);
                context.Response.End();
            }
            catch (Exception ex)
            {
                EventsLog.WriteLog("程序错误：" + ex.Message);
            }
        }
        public void GetMenuChildNode(HttpContext context)
        {
            try
            {
                var id = context.Request["MenuId"];
                if (string.IsNullOrEmpty(id)) return;
                var bll = new MenuBLL();
                var qcmodel = new MenuQcEntity
                {
                    MenuId = id,
                    PageIndex = Convert.ToInt32(context.Request["pageIndex"]),
                    PageSize = Convert.ToInt32(context.Request["pageSize"]),
                    SortField = context.Request["sortField"],
                    SortOrder = context.Request["sortOrder"]
                };
                var json = bll.GetMenuChildNode(qcmodel);
                context.Response.Write(json);
                context.Response.End();
            }
            catch (Exception ex)
            {
                EventsLog.WriteLog("程序错误：" + ex.Message);
            }
        }
        public void GetMenuInfo(HttpContext context)
        {
            try
            {
                var id = context.Request["MenuId"];
                if (string.IsNullOrEmpty(id)) return;
                var json = new MenuBLL().GetMenuInfo(id);
                context.Response.Write(json);
                context.Response.End();
            }
            catch (Exception ex)
            {
                EventsLog.WriteLog("程序错误：" + ex.Message);
            }
        }
        public void AddMenu(HttpContext context)
        {
            try
            {
                var data = context.Request["data"];
                new MenuBLL().AddMenu(data);
            }
            catch (Exception ex)
            {
                EventsLog.WriteLog("程序错误：" + ex.Message);
            }
        }
        public void ModifyMenu(HttpContext context)
        {
            try
            {
                var data = context.Request["data"];
                new MenuBLL().ModifyMenu(data);
            }
            catch (Exception ex)
            {
                EventsLog.WriteLog("程序错误：" + ex.Message);
            }
        }
        public void RemoveMenu(HttpContext context)
        {
            try
            {
                var id = context.Request["MenuId"];
                if (string.IsNullOrEmpty(id)) return;
                new MenuBLL().Remove(id);
            }
            catch (Exception ex)
            {
                EventsLog.WriteLog("程序错误：" + ex.Message);
            }
        }
        public void RemoveParentMenuNode(HttpContext context)
        {
            try
            {
                var id = context.Request["MenuId"];
                if (string.IsNullOrEmpty(id)) return;
                new MenuBLL().RemoveParentMenuNode(id);
            }
            catch (Exception ex)
            {
                EventsLog.WriteLog("程序错误：" + ex.Message);
            }
        }
        public void ModifyParentMenuNode(HttpContext context)
        {
            try
            {
                var data = context.Request["data"];
                new MenuBLL().ModifyParentMenuNode(data);
            }
            catch (Exception ex)
            {
                EventsLog.WriteLog("程序错误：" + ex.Message);
            }
        }
        public void AddParentMenuNode(HttpContext context)
        {
            try
            {
                var data = context.Request["data"];
                new MenuBLL().AddParentMenuNode(data);
            }
            catch (Exception ex)
            {
                EventsLog.WriteLog("程序错误：" + ex.Message);
            }
        }
        #endregion

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}